package pnu.ssm.adapter;

import java.util.ArrayList;

import pnu.ssm.appinfo.Child;
import pnu.ssm.sbmother.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ChildListAdapter extends BaseAdapter{
	Context context;
	LayoutInflater Inflater;
	ArrayList<Child> childList;
	int layout;
	
	public ChildListAdapter(Context context, int layout, ArrayList<Child> childList){
		this.context = context;
		this.Inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.childList = childList;
		this.layout = layout;
	}
	
	@Override
	public int getCount() {
		return childList.size();
	}

	@Override
	public String getItem(int position) {
		return childList.get(position).getChildName();
	}
	
	public String getChildNum(int position){
		return childList.get(position).getChildNum();
	}
	
	public String getChildType(int position){
		return childList.get(position).getChildType();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null)
			convertView = Inflater.inflate(layout, parent, false);
		final int pos = position;
		final TextView tvChildName = (TextView)convertView.findViewById(R.id.tv_child_name);
		final TextView tvChildType = (TextView)convertView.findViewById(R.id.tv_child_type);
		
		Child child = childList.get(pos);
		tvChildName.setText(child.getChildName());
		tvChildType.setText(child.getChildType());
		
		return convertView;
	}
}
